// Assert.cs
//
// Copyright (c) 2007 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Linq;
using System.Diagnostics;

namespace Supremacy.Utility
{
    public class AssertionFailedException : Exception
    {
        public AssertionFailedException(string condition)
            : base("Assertion failed: " + condition) {}
    }

    public static class Assert
    {
        public static void True(bool value)
        {
            Trace.Assert(value, String.Format("({0}) is true", value));
        }

        public static void Equal<T>(T a, T b)
        {
            Trace.Assert(Equals(a, b), String.Format("{0} == {1}", a, b));
        }

        public static void NotEqual<T>(T a, T b)
        {
            Trace.Assert(!Equals(a, b), String.Format("{0} != {1}", a, b));
        }

        public static void GreaterThan<T>(T a, T b) where T : IComparable
        {
            Trace.Assert(a.CompareTo(b) > 0, String.Format("{0} > {1}", a, b));
        }

        public static void GreaterThanOrEqual<T>(T a, T b) where T : IComparable
        {
            Trace.Assert(a.CompareTo(b) >= 0, String.Format("{0} >= {1}", a, b));
        }

        public static void LessThan<T>(T a, T b) where T : IComparable
        {
            Trace.Assert(a.CompareTo(b) < 0, String.Format("{0} < {1}", a, b));
        }

        public static void LessThanOrEqual<T>(T a, T b) where T : IComparable
        {
            Trace.Assert(a.CompareTo(b) <= 0, String.Format("{0} <= {1}", a, b));
        }

        public static void IsPositive<T>(T value) where T : IComparable
        {
            Trace.Assert(value.CompareTo(0) > 0, String.Format("{0} > 0", value));
        }

        public static void IsNonNegative<T>(T value) where T : IComparable
        {
            Trace.Assert(value.CompareTo(0) >= 0, String.Format("{0} >= 0", value));
        }

        public static void IsNegative<T>(T value) where T : IComparable
        {
            Trace.Assert(value.CompareTo(0) < 0, String.Format("{0} < 0", value));
        }
    }
}